# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution:
    def oddEvenList(self, head: ListNode) -> ListNode:
        if not head:
            return None
        now_note, count = head.next, 0
        ji_wei, ou_wei = head, ListNode(None)
        ou_tou = ou_wei
        while now_note:
            if count % 2 == 1:
                ji_wei.next, ji_wei = now_note, now_note
            else:
                ou_wei.next, ou_wei = now_note, now_note
            now_note = now_note.next
            count += 1
        ji_wei.next, ou_wei.next = ou_tou.next, None
        return head
